﻿using System;
using housingsafety.server.Caching.Core;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;

namespace housingsafety.server.Caching.Redis
{
    public static class RedisCacheServiceCollectionExtensions
    {
        public static IServiceCollection AddDistributedRedisCache(this IServiceCollection services, Action<RedisCacheOptions> setupAction)
        {
            Requires.NotNull(setupAction, nameof(setupAction));
            services.AddOptions();
            services.Configure(setupAction);
            services.Add(ServiceDescriptor.Singleton<IDistributedCache, RedisCache>());
            return services;
        }
    }
}
